<?php
// 数据库配置信息
$db_configs = array(
    'default' => array(
        'host' => 'localhost',
        'username' => 'news_system',
        'password' => 'news_system',
        'dbname' => 'news_system',
        'manage' => true
    ),
    'library_new' => array(
        'host' => 'localhost',
        'username' => 'library_new',
        'password' => 'library_new',
        'dbname' => 'library_new'
    ),
    // 可以添加更多配置
);

define('WEB_NAME', '新闻管理系统');
define('DEFAULT_CONFIG_ID','default');

/**
 * 建立数据库连接
 * @param string $config_id 配置ID，默认为'default'
 * @return mysqli 数据库连接对象
 */
function getDbConnection($config_id = DEFAULT_CONFIG_ID) {
    global $db_configs;
    
    // 检查配置是否存在
    if (!isset($db_configs[$config_id])) {
        die("数据库配置不存在: " . $config_id);
    }
    
    $config = $db_configs[$config_id];
    $conn = new mysqli($config['host'], $config['username'], $config['password'], $config['dbname']);
    #$conn = new mysqli($config['host'], $config['username'], $config['password'], $config['dbname'],3306,MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT);
    // 检查连接
    if ($conn->connect_error) {
        die("数据库连接失败: " . $conn->connect_error);
    }

    return $conn;
}
?>